<template>
  <view v-if="type == 0">
    <view class="canvas">
      <canvas canvas-id="barcode"></canvas>
    </view>
    <text class="number">{{ Messages.CpnNumber }}</text>
    <view class="divider"></view>
    <view class="box">
      <text class="title">{{ Messages.CpnName }}</text>
      <view class="explain">
        <text>使用规则:</text>
        <text>满{{ Messages.FMinValue }}元,立减{{ Messages.FValue }}元</text>
      </view>
      <view class="explain">
        <text>使用门店:</text>
        <text>{{ Messages.CorpName }}</text>
      </view>
      <view class="explain">
        <text>有效时间:</text>
        <text>{{ Messages.StartTime }}-{{ Messages.EndTime }}</text>
      </view>
    </view>
  </view>
  <view v-else>
    <view class="canvas">
      <canvas canvas-id="barcodeCard"></canvas>
    </view>
    <text class="number"></text>
    <view class="divider"></view>
    <view class="box">
      <!-- <view class="card-number">
				<text style="float: left;">开卡总量:<text class="ci_number">1次</text></text>
				<text style="float: right;">卡内剩余:<text class="ci_number">1次</text></text>
			</view> -->
      <text class="title">{{ Messages.FName }}</text>
      <view class="explain">
        <text>次卡编码:</text>
        <text>{{ Messages.FNumber }}</text>
      </view>
      <view class="explain">
        <text>剩余次数:</text>
        <text>{{ Messages.FQty }}</text>
      </view>
      <view class="explain">
        <text>有效期到:</text>
        <text>{{ Messages.FStatusDesc }}</text>
      </view>
      <view class="explain">
        <text>适用门店:</text>
        <text>{{ Messages.FStockName }}</text>
      </view>
    </view>
  </view>
</template>

<script>
import { reqPost } from "../../common/http.request";

export default {
  data() {
    return {
      id: 0,
      type: "",
      Messages: {},
    };
  },
  async onLoad(options) {
    this.id = options.id;
    this.type = options.type;
/*     if (options.type == 0) {
      await this.loaded("membershop/CouponDtl", { sendId: this.id });
    } else { */
      await this.loaded("MemberTimeDtl", { id: this.id });
    // }
  },
  methods: {
    async loaded(url, data) {
      try {
        const { Data } = await reqPost(url, data);
        this.Messages = Data;
        let member = uni.getStorageSync("Members");
        let storesID = uni.getStorageSync("stockId");
        let number =
          Data.FEntryID.toString() + "-" + member[0].MemberId + "-" + storesID;
        number = Data.CpnNumber || number;
        let id = this.type == 0 ? "barcode" : "barcodeCard";
        this.$canvas.barcode(id, number, 480, 380);
      } catch (err) {
        console.log(err, "err");
      }
    },
  },
};
</script>

<style lang="scss">
canvas {
  height: 100rpx;
  width: 500rpx;
}
.canvas {
  padding: 30rpx;
  height: 150rpx;
  width: 500rpx;
  margin: auto;
}
.number {
  width: 100%;
  height: 50rpx;
  line-height: 50rpx;
  display: inline-block;
  text-align: center;
  font-weight: bold;
  font-size: 32rpx;
  color: #000;
}
.divider {
  width: 100%;
  border: 4rpx dashed #f1f1f1;
  margin: 20rpx 0;
}
.box {
  padding: 0 30rpx;
  height: auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;
  .title {
    font-size: 38rpx;
    font-weight: bold;
    color: #000;
    text-align: center;
  }
  .explain {
    width: 100%;
    line-height: 40rpx;
    margin: 20rpx 0;
    text:first-child {
      color: #a2a2a2;
      margin-right: 20rpx;
      float: left;
    }
    text:last-child {
      color: #000;
      display: inline-block;
      width: 530rpx;
      float: left;
    }
  }
  .card-number {
    width: 100%;
    line-height: 40rpx;
    margin: 20rpx 0;
    color: #a2a2a2;
    .ci_number {
      color: #4cd964;
      margin-left: 20rpx;
    }
  }
}
</style>
